/* GetMacName は、model プロパティ文字列を
* C 形式 (ヌルターミネートされた文字列) で返す。
* Input macName - バッファへのポインタ。呼び出しが成功すると、
* model name プロパティ名はここに返される。
*
* Output function result - noErr は、機種名の読み出しに成功した
* ことを示す。
* macName - noErr の場合、機種名のプロパティが格納される。
*
* 注意
* 呼び出し元ルーチンは、macName の廃棄も行うこと。
* その場合はDisposePtr を使用する。
*/
OSStatus GetMacName (StringPtr * macName) {
OSStatus err = noErr;
RegEntryID compatibleEntry;
RegPropertyValueSize length;
RegCStrEntryNamePtr compatibleValue;
if (macName != nil) {
*macName = 0;
err = RegistryEntryIDInit (&compatibleEntry);
if (err == noErr) {
err = RegistryCStrEntryLookup (nil, "Devices:device-tree", &compatibleEntry);
}
if (err == noErr) {
err = RegistryPropertyGetSize (&compatibleEntry, "compatible", &length);
}
if (err == noErr) {
compatibleValue = (RegCStrEntryNamePtr)NewPtr (length);
err = MemError ();
}
if (err == noErr) {
err = RegistryPropertyGet (&compatibleEntry, "compatible", compatibleValue, &length);
}
if (err == noErr) {
SetPtrSize (compatibleValue, strlen (compatibleValue) + 1);
/* SetPtrSize shouldn't fail because we are shrinking the pointer, but make sure. */
err = MemError ();
}
if (err == noErr) {
*macName = c2pstr (compatibleValue);
}
(void)RegistryEntryIDDispose (&compatibleEntry);
}
return err;
}
/* GetMacSpeed は CPU ノードの clock-frequency プロパティを返す
*
* Output function result - noErr は CPU ノードの clock-frequency
* プロパティが正常に読み出せたことを示す。
* cpuFreq - noErr の場合、clock-frequency プロパティが格納される。
* clock-frequency が読み出せなかった場合は 0 にセットされる。
*/
OSStatus GetMacSpeed (UInt32 * cpuFreq) {
OSStatus err = noErr;
RegEntryID cpuEntry;
RegEntryIter cookie = nil;
RegEntryIterationOp iterOp = kRegIterDescendants;
unsigned long cpuSpeedSize = sizeof (unsigned long);
char * cpuValue = "cpu";
Boolean done;
if (cpuFreq != nil) {
*cpuFreq = 0;
} else {
cpuSpeedSize = 0;
}
if (err == noErr) {
err = RegistryEntryIDInit (&cpuEntry);
}
if (err == noErr) {
err = RegistryEntryIterateCreate (&cookie);
}
if (err == noErr) {
err = RegistryEntrySearch (&cookie, iterOp, &cpuEntry, &done, "device_type",
cpuValue, strlen (cpuValue) + 1);
if (done != true && err == noErr) {
(void)RegistryPropertyGet (&cpuEntry, "clock-frequency", cpuFreq, &cpuSpeedSize);
}
}
(void)RegistryEntryIDDispose (&cpuEntry);
(void)RegistryEntryIterateDispose (&cookie);
return err;
}
|